/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 100;

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    bool flag = false;
    int pre = 0;
    for (int i = 1; i <= n; ++i) {
      int in;
      cin >> in;
      if (!flag && (in | x) == x) {
        pre |= in;
      }
      if ((in | x) != x) {
        flag = true;
      }
    }
    flag = false;
    for (int i = 1; i <= n; ++i) {
      int in;
      cin >> in;
      if (!flag && (in | x) == x) {
        pre |= in;
      }
      if ((in | x) != x) {
        flag = true;
      }
    }
    flag = false;
    for (int i = 1; i <= n; ++i) {
      int in;
      cin >> in;
      if (!flag && (in | x) == x) {
        pre |= in;
      }
      if ((in | x) != x) {
        flag = true;
      }
    }
    cout << (pre == x ? "Yes" : "No") << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Tenzing and Books.in", "r", stdin);
  freopen("B. Tenzing and Books.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
